import axios from 'axios';
import type { RouteRecordNormalized } from 'vue-router';
import { UserState } from '@/store/modules/user/types';

export interface LoginData {
  username: string;
  password: string;
}

export interface LoginRes {
  refresh: string;
  access: string;
}

// 登录
export function login(data: LoginData) {
  return axios.post<LoginRes>('/auth/login/', data);
}
//获取用户信息
export function getUserInfo() {
  return axios.get<UserState>('/auth/userinfo/');
}
// 更新用户信息
export function updateUserInfo(data: any) {
  return axios.put<UserState>('/auth/userinfo/', data);
}
// 更新用户密码
export function updatePassward(data: any) {
  return axios.post<UserState>('/auth/setPwd/', data);
}
// 更新用户头像
export function userUploadApi( data: any) {
  return axios.post('/auth/avatar/', data);
}


export function logout() {
  return axios.post<LoginRes>('/api/user/logout');
}
export function getMenuList() {
  return axios.post<RouteRecordNormalized[]>('/api/user/menu');
}